package cn.gson.springboot.controller.aftercontroller;

import cn.gson.springboot.model.pjos.*;
import cn.gson.springboot.model.service.afterservice.CucheckService;
import cn.gson.springboot.model.vo.aftervo.CucheckVo;
import cn.gson.springboot.model.vo.aftervo.ExpenseVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/che")
public class CucheckController {

    @Autowired
    CucheckService sc;

    @RequestMapping("/check-page")
    @ResponseBody
    public Map<String,Object> checkPage(Integer cutId, String apprTitle, Integer empId, Integer currPage, Integer pageSize){
        Page<Object> obj = PageHelper.startPage(currPage, pageSize);
        List<CucheckVo> check = sc.selectCucheckPage(cutId, apprTitle, empId);

        Map<String,Object> map = new HashMap<>();
        map.put("rows",obj.getResult());        //分页后的数据，一页展示多少数据
        map.put("total",obj.getTotal());        //总条数
        return map;
    }

    @RequestMapping("/check-type")
    @ResponseBody
    public List<CucheckType> checkType(){
        return sc.selectCheckTypeAll();
    }

    @RequestMapping("/update-check")
    @ResponseBody
    public void updateCheck(Integer empId, Integer apprId, String apprView, Integer trialId, String title){
        sc.addCheck(empId, apprId, apprView, trialId, title);
    }

    @RequestMapping("/deliver-check")
    @ResponseBody
    public void deliverCheck(Integer empId, Integer apprId, Integer employeesId, String apprView, Integer trialId, String title){
        sc.deliver(empId, apprId, employeesId, apprView, trialId, title);
    }

    @RequestMapping("/delete-check")
    @ResponseBody
    public void deleteCheck(Integer empId, Integer apprId, String apprView, Integer trialId, String title){
        sc.delete(empId, apprId, apprView, trialId, title);
    }

    @RequestMapping("/query-check")
    @ResponseBody
    public CucheckVo queryCheck(Integer apprId){
        return sc.check(apprId);
    }

    @RequestMapping("/exps-check")
    @ResponseBody
    public ExpenseVo expsCheck(Integer apprId){
        return sc.checkExpsByApprId(apprId);
    }

    @RequestMapping("/evet-check")
    @ResponseBody
    public Evection evetCheck(Integer apprId){
        return sc.checkEvetByApprId(apprId);
    }

    @RequestMapping("/check-title")
    @ResponseBody
    public String checkTitle(Integer apprId){
        return sc.titleApprId(apprId);
    }

    @RequestMapping("/check-details")
    @ResponseBody
    public List<CheckDetails> checkDetails(Integer apprId){
        return sc.selectCheckDetails(apprId);
    }

    @RequestMapping("/appr-ids")
    @ResponseBody
    public Integer apprIdsById(Integer apprId){
        return sc.selectApprIdsById(apprId);
    }

    @RequestMapping("/deliver-id")
    @ResponseBody
    public List<CheckDetails> deliverId(String apprTitle,Integer apprIds){
        return sc.selectDeliverId(apprTitle, apprIds);
    }

    @RequestMapping("/check-id")
    @ResponseBody
    public Integer checkId(String apprTitle, Integer apprIds){
        return sc.selectCheckById(apprTitle, apprIds);
    }
}
